package com.hkts.management.imgrecord.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.management.imgrecord.entity.HktsOrderImgrecord;
import com.hkts.management.imgrecord.mapper.HktsOrderImgrecordMapper;
import com.hkts.management.imgrecord.service.IHktsOrderImgrecordService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-07-12
 */
@Service
@Transactional
public class HktsOrderImgrecordServiceImpl extends ServiceImpl<HktsOrderImgrecordMapper, HktsOrderImgrecord> implements IHktsOrderImgrecordService {


    @Autowired
    private HktsOrderImgrecordMapper hktsOrderImgrecordMapper;

    @Override
    public IPage<HktsOrderImgrecord> selectPage(Page<HktsOrderImgrecord> page, HktsOrderImgrecord hktsOrderImgrecord) {
        QueryWrapper<HktsOrderImgrecord> query = Wrappers.query();
        QueryWrapper<HktsOrderImgrecord> entityWrapper = getEntityWrapper(query, hktsOrderImgrecord);
        return hktsOrderImgrecordMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HktsOrderImgrecord> selectList(HktsOrderImgrecord hktsOrderImgrecord) {
        QueryWrapper<HktsOrderImgrecord> query = Wrappers.query();
        QueryWrapper<HktsOrderImgrecord> entityWrapper = getEntityWrapper(query, hktsOrderImgrecord);
        return hktsOrderImgrecordMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HktsOrderImgrecord> getEntityWrapper(QueryWrapper<HktsOrderImgrecord> entityWrapper, HktsOrderImgrecord hktsOrderImgrecord) {
        //条件拼接
        if (StringUtils.isNotBlank(hktsOrderImgrecord.getOrderId())) {
            entityWrapper.like(HktsOrderImgrecord.ORDER_ID, hktsOrderImgrecord.getOrderId());
        }
        if (StringUtils.isNotBlank(hktsOrderImgrecord.getRecord())) {
            entityWrapper.like(HktsOrderImgrecord.RECORD, hktsOrderImgrecord.getRecord());
        }
        if (StringUtils.isNotBlank(hktsOrderImgrecord.getCreateUser())) {
            entityWrapper.like(HktsOrderImgrecord.CREATE_USER, hktsOrderImgrecord.getCreateUser());
        }

        return entityWrapper;
    }

    public List<HktsOrderImgrecord> getHktsOrderImgrecordByOrderId(String orderId) {
        QueryWrapper<HktsOrderImgrecord> query = Wrappers.query();
        query.lambda().eq(HktsOrderImgrecord::getOrderId,orderId);

        return hktsOrderImgrecordMapper.selectList(query);
    }
}
